/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(){

  

   $(document).mousemove(function(e){
       if (e.pageX>=375 && e.pageX<=400 && e.pageY>=45 && e.pageY<=70)
       {
           document.getElementById("searchpublication").style.cursor='pointer';
       }
       else
       {
           document.getElementById("searchpublication").style.cursor='text';
       }
       
     
   });


   $(document).click(function(e){
      if (e.pageX>=375 && e.pageX<=400 && e.pageY>=45 && e.pageY<=70)
      {
          var $url = "http://"+location.hostname+"/publication/refreshRBISResearchList?rStatus=" + document.getElementById('hfSelectionStatus').value + "&pg=1&rSearchtext="+document.getElementById('searchpublication').value;
          $.post($url, {}, function(data) {
              $('#tblRBISResearches').html(data);
          });
      }
   });
   
});



$(document).ready(function() {
    /*
     * If user clicks Uploaded Research link (placed next to user profile picture) then
     * system should redirect to home with current user's publication list.
     * Therefore appending a URL parameter on Uploaded Research link click even and
     * fetching that parameter here as this function executes on Home Page load.
     */
    var $url = "http://"+location.hostname+"/publication/refreshRBISResearchList?pg=1&tid=" + document.getElementById('hfTid').value;

    if(document.getElementById('hfUid').value != "")
        $url += "&id=" + document.getElementById('hfUid').value;

    if(document.getElementById('searchpublication').value != "")
        $url += "&rSearchtext=" + document.getElementById('searchpublication').value;

 
    $.post($url, {}, function(data) {
        $('#tblRBISResearches').html( data);
    });
 });
 


function showAbstract(id)
{

    document.getElementById("td"+id).style.overflow="visible";
    document.getElementById("td"+id).style.height="auto";
    $("#"+id).hide();
    
    
}
function showMoreResearches(objTab, tabValue, userId, hfResearchSelectorID, hfpgNumber, isTabClicked)
{
    var pgNumber = document.getElementById(hfpgNumber);
    if(isTabClicked)
    {
        pgNumber.value = 1;
        $('#tblRBISResearches').html("");
    }
    else
        pgNumber.value = parseInt(pgNumber.value) +  1;

    return loadRBISResearchList(objTab, tabValue, userId, hfResearchSelectorID, pgNumber.value);
}

function setActiveTab(objTab)
{
    var lnkAllData = document.getElementById('lnkAll');
    var lnkPublishedData = document.getElementById('lnkMine');
    var lnkPendingData = document.getElementById('lnkPendingPublicationList');
    var lnkCollaborationData = document.getElementById('lnkCollaborationData');

    if(objTab)
    {
        // Remove activeTab CSS class from all tabs first
        removeCSSClass(lnkAllData, 'activeTab');
        removeCSSClass(lnkPublishedData, 'activeTab');
        removeCSSClass(lnkCollaborationData, 'activeTab');

        // Pending tab can be null
        if(lnkPendingData)
            removeCSSClass(lnkPendingData, 'activeTab');

        // Set activeTab CSS class on current object (tab)
        objTab.className += ' activeTab';
    }
}

function loadRBISResearchList(objTab, tabValue, userId, hfResearchSelectorID, pgNo)
{
    setActiveTab(objTab);

    var flagResearchSelection = document.getElementById(hfResearchSelectorID);

    // Storing selected button value in a hidden value so that on click of more++
    // data can be retrieved according to selected button
    if(flagResearchSelection)
        flagResearchSelection.value = tabValue;

    var $url = "http://"+location.hostname+"/publication/refreshRBISResearchList?tid=" + tabValue + "&pg=" + pgNo + (userId == 0? "" : ("&id=" + userId))+ "&rSearchtext=" + document.getElementById('searchpublication').value;

    //$("#tdResearchData").html("No data found");
    //$("#tblRBISResearches").html('<img src="/images/loading/loading9.gif"/>');
    $.post($url, {}, function(data) {
        
        $('#tdMore').remove();
        
        $('#tblRBISResearches').html($('#tblRBISResearches').html() + data);
    });
    return false;
}

function searchPublication_Changed(searchText, objTab, tabValue, userId, hfResearchSelectorID, hfpgNumber, isTabClicked)
{
    var registraionBanner = document.getElementById('dvRegistrationBanner');

    if(registraionBanner)
    {
        if(searchText == "")
            $('#dvRegistrationBanner').attr('style', 'display:block');
        else
            $('#dvRegistrationBanner').attr('style', 'display:none');
    }

    return showMoreResearches(objTab, tabValue, userId, hfResearchSelectorID, hfpgNumber, isTabClicked);
}